package com.longxiao.vo;

import com.longxiao.enums.ResultCode;

public class CommResult<T> {
	
	private String code;
	
	private String msg;
	
	private T data;
	
	public static <T> CommResult<T> createResult(String code, String msg, T data) {
		CommResult<T> result = new CommResult<T>(code, msg, data);
		return result;
	}

	@Override
	public String toString() {
		return "CommResult{" +
				"code='" + code + '\'' +
				", msg='" + msg + '\'' +
				", data=" + data +
				'}';
	}

	public static <T> CommResult<T> succResult(ResultCode code, T data) {
		return createResult(code.getCode(), "OK", data);
	}

//	public static <T> CommResult<T> succResult(ResultCode code, String msg) {
//		return createResult(code.getCode(), msg, null);
//	}

	public static <T> CommResult<T> succResult(T data) {
		return createResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getCn(), data);
	}
	
	public static <T> CommResult<T> succResult(ResultCode code, String msg, T data) {
		return createResult(code.getCode(), msg, data);
	}

	public static <T> CommResult<T> failResult(String code, String msg) {
		return createResult(code, msg, null);
	}

	public static <T> CommResult<T> failResult(ResultCode code, String msg) {
		return createResult(code.getCode(), msg, null);
	}

	
	public CommResult(String code, String msg) {
		this.code = code;
		this.msg = msg;
	}
	
	public CommResult(String code, String msg, T data) {
		this.code = code;
		this.msg = msg;
		this.data = data;
	}
	
	
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}
	
	
	
}
